import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/components/back_btn_icon.dart';
import 'package:share_fit/app/controllers/device/remind/remind_logic.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/color_const.dart';
import 'package:share_fit/generated/locales.g.dart';

class RemindPage extends StatelessWidget {

  final logic = Get.put(RemindLogic());
  final state = Get.find<RemindLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(LocaleKeys.remind.ts, style: TextStyle(fontSize: 54.sp, color: ColorConst.btnFontColor),),
        centerTitle: true,
        leading: BackBtnIcon(onTap: () => Get.back()),
        // leading: IconButton(
        //   padding: EdgeInsets.only(left: 15,),
        //   icon: Image.asset("assets/images/space/icon_appbar_arrow_back.png"),
        //   onPressed: () { Get.back(); },
        //   // child: Image.asset("images/icon_appbar_arrow_back.png"),
        // ),
        // leadingWidth: 25,
      ),
      body: ListView(
        children: [
          Container(
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(10),
                color: Colors.white
            ),
            margin: EdgeInsets.fromLTRB(42.w, 100.h, 42.w, 0),
            // child: Column(
            //   children: widgets,
            // )

            child: GetBuilder<RemindLogic>(
              id: 'update_datas',
              builder: (_) {
                return ListView.separated(
                    shrinkWrap: true,
                    physics: NeverScrollableScrollPhysics(),
                    itemBuilder: (BuildContext context, int index) {
                      return _buildListTitle(index);
                    },
                    separatorBuilder: (BuildContext context, int index) {
                      return Container(height: 1,);
                    },
                    itemCount: state.itemDatas.length
                );
              },
            ),
          ),
          Container(
              margin: EdgeInsets.fromLTRB(42.w, 132.h, 42.w, 130.h),
              child: ElevatedButton(
                onPressed: () {Get.toNamed('/device/settings/remind/add');},
                style: ButtonStyle(
                    padding: MaterialStateProperty.all(EdgeInsets.only(top: 66.h, bottom: 66.h)),
                    backgroundColor: MaterialStateProperty.all(Color(0xFFFFFFFF)),
                    shape: MaterialStateProperty.all(RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(10)
                    ))
                ),
                child: Image(
                  width: 50.w,
                  height: 50.h,
                  image: const AssetImage("assets/images/device/icon_remind_add.png"),),)
          )
        ],
      ),
    );
  }

  Widget _buildListTitle(int index) {
    return Column(
      children: [
        GestureDetector(
          behavior: HitTestBehavior.opaque,
          onTap: ()=>{
            print(index.toString())
          },
          child: Container(
            padding: EdgeInsets.fromLTRB(56.w, 72.h, 36.w, 72.h),
            child: Row(
              children: [
                Text(state.itemDatas[index].title, style: TextStyle(fontSize: 42.sp),),
                Expanded(child: Container()),
                Text(state.itemDatas[index].time, style: TextStyle(fontSize: 42.sp),),
                SizedBox(width: 76.w,),
                Image.asset("assets/images/space/icon_space_arrow.png", width: 8,height: 18,)
              ],
            ),
          ),
        ),
        Opacity(opacity: index<state.itemDatas.length-1?1:0, child: Divider(height: 1,),)
      ],
    );
  }


}